package com.atguigu.yygh.user.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import lombok.Data;
import org.springframework.jdbc.object.SqlFunction;
import org.springframework.util.StringUtils;

@Data
public class SqlUtil<T> {

    private QueryWrapper<T> wrapper;

    public SqlUtil(Dynamic<T> dynamic) {
        this.wrapper = dynamic.wrapper;
    }

    public static final class Dynamic<T> {

        private QueryWrapper<T> wrapper = new QueryWrapper<>();

        public Dynamic<T> eq(String column,Object val){
            if(!StringUtils.isEmpty(val)) {
                this.wrapper.eq(column, val);
            }
            return this;
        }

        public Dynamic<T> ge(String column,Object val){
            if(!StringUtils.isEmpty(val)) {
                this.wrapper.ge(column, val);
            }
            return this;
        }

        public Dynamic<T> le(String column,Object val){
            if(!StringUtils.isEmpty(val)) {
                this.wrapper.le(column, val);
            }
            return this;
        }

        public Dynamic<T> like(String column,Object val){
            if(!StringUtils.isEmpty(val)) {
                this.wrapper.like(column, val);
            }
            return this;
        }

        public QueryWrapper<T> build(){
           return new SqlUtil<>(this).getWrapper();
        }
    }

}
